package com.eckey.lab.feign;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author: Marinc
 * @CreateTime: 2023-07-27  14:40
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserFeign> {
    public UserFeign create(Throwable throwable) {
        return new UserFeign() {
            public String findOrderByUserId() {
                throw new RuntimeException("查询订单失败，用户不存在");
            }

            public String getUserById(@RequestParam("id") Integer id) {
                throw new RuntimeException("用户不存在");
            }

            public String deduct(@RequestParam("userId") Integer userId, @RequestParam("totalPrice") Integer totalPrice) {
                {
                    throw new RuntimeException("金额扣减异常");
                }
            }
        };
    }
}
